<?php
namespace Home\Controller;
use Think\Controller;
use Home\Controller\Common;
class IndexController extends Controller {
    public function index(){
        if (isset ($_SERVER['HTTP_USER_AGENT'])) {
              $clientkeywords = array (
               'nokia',
               'sony',
               'ericsson',
               'mot',
               'samsung',
               'htc',
               'sgh',
               'lg',
               'sharp',
               'sie-',
               'philips',
               'panasonic',
               'alcatel',
               'lenovo',
               'iphone',
               'ipod',
               'blackberry',
               'meizu',
               'android',
               'netfront',
               'symbian',
               'ucweb',
               'windowsce',
               'palm',
               'operamini',
               'operamobi',
               'openwave',
               'nexusone',
               'cldc',
               'midp',
               'wap',
               'mobile'
              );
              // 从HTTP_USER_AGENT中查找手机浏览器的关键字
            // $_SERVER['HTTP_USER_AGENT']='android';
              // var_dump($_SERVER['HTTP_USER_AGENT']);die;
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
                $this->Mobleindex();
            }else{
                $this->PCindex();
            }
        }
    }

    /****
    Pc端的代码站是
    ***/
    public function PCindex(){
        $picture=D('Pictureinfo');

        // 主题的图片的信息情况
        $result=$picture->pictureinfo();
        $restcell=array_slice($result['data'], 1,(count($result['data'])-1));

        // 商品的产品信息情况
        $goodlist=D('Cate');
        $goodinfolist=$goodlist->goodslist();
        // var_dump('eeeee');die;
        $this->assign('url','https://m3.tuniucdn.com/fb2/t1/G5/M00/7E/A2/Cii-sltIb2-ITSZ1AAEaPXz4TngAAKKHwB9vAkAARpV83.jpeg');
        $this->assign('result',$result);
        $this->assign('restcell',$restcell);
        // var_dump($restcell);
        // var_dump($result);die;
        $resultmo=array_values(mongofunc());
        $resulta=array();
        foreach ($resultmo as $key => $value) {
          if(!isset($resulta[$value['title']])){
            $resulta[$value['title']]=array();
          }
          $resulta[$value['title']][]=array('title'=>$value['title'],'singleinfo'=>$value['singleinfo']);
        }
        $resultmo=array_reverse($resulta,true);
        // foreach ($resultmo as $key => $value) {
        //   // var_dump($key);
        //   if($key=='超值套餐'){
        //     foreach ($value as $keya => $valuea) {
        //       var_dump($keya);
        //     }
        //   }
          
        //   var_dump('expression');
        // }

        // var_dump($resultmo['超值机票'][0]);
        // die;
        $this->assign('resultmo',$resultmo);
        $this->assign('resultmoaa',$resultmo);
        $this->assign('resultmobb',$resultmo);
        $this->assign('goodinfolist',$goodinfolist['data']);
    	  $this->display('index/index');
    }

    /****
    Mobleindex()移动端的代码展示
    ****/
    public function Mobleindex(){
        $picture=D('Pictureinfo');

        // 主题的图片的信息情况
        $result=$picture->pictureinfo();
        $restcell=array_slice($result['data'], 1,(count($result['data'])-1));

        $goodlist=D('Cate');
        $goodinfolist=$goodlist->goodslist();
        $this->assign('goodinfolist',$goodinfolist['data']);
        $this->assign('result',$result);
        $this->assign('restcell',$restcell);
        $this->display('mobel/index');
    }



    public function viewdetail(){
    	$id=I('get.picture');
      if(strpos($id, '\\')){
        $ida=explode('\\', $id)[1];
      }else{
        $ida=explode('/', $id)[count(explode('/', $id))-1];
      }
      // var_dump($ida);
      $picture=D('Pictureinfo');
    	$result=$picture->pictureinfo($ida);

      $this->assign('result',$result);
      // var_dump($result);die;
    	$this->assign('id',$id);
    	$this->display('index/viewdetail');
 
    }

    /****
    Pclogin()电脑PC端登陆;
    ***/
    public function Pclogin(){
      $this->assign('info','0');
      $this->assign('index',$_GET['index']);
      $this->display('index/Pclogin');
    }

    /****
    ****Pcloginentry()电脑PC端登陆
    ***/
    public function Pcloginentry(){
      // 用户的信息情况

      $user=D('Websites');
      $inforesult=$user->loginsure($_POST);
      if($inforesult['success']=='1'){
        $this->assign('info',$inforesult);
        $this->display('index/Pclogin');
        return;
      }
     

      // 主题的图片的信息情况
      $picture=D('Pictureinfo'); 
      $result=$picture->pictureinfo();
      $restcell=array_slice($result['data'], 1,(count($result['data'])-1));

      // 商品的产品信息情况
      $goodlist=D('Cate');
      $goodinfolist=$goodlist->goodslist();
      // var_dump($goodinfolist);die;
      $this->assign('info',$inforesult);
      $this->assign('url','https://m3.tuniucdn.com/fb2/t1/G5/M00/7E/A2/Cii-sltIb2-ITSZ1AAEaPXz4TngAAKKHwB9vAkAARpV83.jpeg');
      $this->assign('result',$result);
      $this->assign('restcell',$restcell);
      $this->assign('goodinfolist',$goodinfolist['data']);
      $this->display('index/index');
    }

    /****
    ******register()新用户注册
    ****/
    public function register(){
      $user=D('Websites');
      $inforesult=$user->registersure($_POST);
      if($inforesult['success']=='0'){
        // 主题的图片的信息情况
        $picture=D('Pictureinfo'); 
        $result=$picture->pictureinfo();
        $restcell=array_slice($result['data'], 1,(count($result['data'])-1));

        // 商品的产品信息情况
        $goodlist=D('Cate');
        $goodinfolist=$goodlist->goodslist();
        $this->assign('info',$inforesult);
        $this->assign('url','https://m3.tuniucdn.com/fb2/t1/G5/M00/7E/A2/Cii-sltIb2-ITSZ1AAEaPXz4TngAAKKHwB9vAkAARpV83.jpeg');
        $this->assign('result',$result);
        $this->assign('restcell',$restcell);
        $this->assign('goodinfolist',$goodinfolist['data']);
        $this->display('index/index');
        return;
      }else{
        $this->assign('info',$result);
        $this->assign('index','1');
        $this->display('index/Pclogin');
        return ;
      }
    }
}




















